import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/util/utils.dart';
import 'package:ls_work/viewmodel/event_manage/event_manage_list_viewmodel.dart';
import 'package:ls_work/widgets/add_image_widget.dart';
import 'package:ls_work/widgets/bottom_input_widget.dart';
import 'package:ls_work/widgets/title_value_widget.dart';

import '../../viewmodel/event_manage/add_event_view_model.dart';

class AddEventPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _AddEventState();
}

class _AddEventState extends BaseMvvmState<AddEventViewModel, AddEventPage> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        TitleValueWidget(
          '长者姓名',
          text: viewModel.selectOld?.name ?? "",
          isRequired: false,
        ).onTap(() {
          viewModel.selectOldInfo();
        }),
        Gaps.dividerLine,
        TitleValueWidget(
          '事件类型',
          text: viewModel.selectedType?.name ?? "",
          isRequired: true,
        ).onTap(() {
          viewModel.selectEventType();
        }),
        Gaps.dividerLine,
        TitleValueWidget(
          '发生时间',
          text: viewModel.dateTime ?? "",
          isRequired: true,
        ).onTap(() {
          viewModel.selectTime();
        }),
        Gaps.dividerLine,
        TitleValueWidget(
          '发生位置',
          text: viewModel.selectedBuilding?.name ?? "",
          isRequired: true,
        ).onTap(() {
          viewModel.selectBuilding();
        }),
        Gaps.dividerLine,
        TitleValueWidget(
          '详细位置',
          text: viewModel.locationAddr ?? "",
          isRequired: true,
        ).onTap(() {
          showBottomInput(context,
              title: '详情位置',
              content: viewModel.locationAddr ?? "", onSubmit: (str) {
            setState(() {
              viewModel.locationAddr = str;
            });
          });
        }),
        Gaps.dividerLine,
        TitleValueWidget(
          '事件经过',
          text: viewModel.eventProcess ?? "",
          isRequired: true,
        ).onTap(() {
          showBottomInput(context,
              title: '事件经过',
              content: viewModel.eventProcess ?? "", onSubmit: (str) {
            setState(() {
              viewModel.eventProcess = str;
            });
          });
        }),
        Gaps.dividerLine,
        AddAndUploadImageWidget(
          (files, modelList) {
            viewModel.files = files;
          },
          files: viewModel.files,
          cameramsg: "拍摄事件登记照片，需要申请您的相机权限",
          photomsg: "从相册选取事件登记照片，需要申请您的相册权限",
        ),
        Container().setWeight(1),
        TextButton(
          onPressed: () {
            viewModel.submitCreate();
          },
          child: CommonText('提交', textColor: Colors.white),
          style: ButtonStyle(
              backgroundColor: WidgetStateProperty.all(Colors.blue),
              minimumSize: WidgetStateProperty.all(
                  Size(MediaQuery.of(context).size.width - 32, 49)),
              shape: WidgetStateProperty.all(StadiumBorder())),
        ),
        SizedBox(
          height: 20,
        )
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text("提报登记"),
        actions: [
          IconButton(onPressed: (){
            Utils.launchTelURL(sosPhone);
          }, icon: Icon(Icons.call))
        ],
      ),
      body: loadingContentWidget,
    );
  }

  @override
  AddEventViewModel createViewModel() {
    return AddEventViewModel(context);
  }

  @override
  void onRetryClick() {
    // TODO: implement onRetryClick
  }
}
